#include "stdafx.h"

#include "Player.h"

CPlayer::CPlayer()
{
	m_nowPos.x = 300;
	m_nowPos.y = 300;
	m_desPos.x = 300;
	m_desPos.y = 300;

	m_image.Load(L"icons\\star.png");
	ImgTransparent(&m_image);

}
CPlayer::~CPlayer()
{

}

void CPlayer::SetPos(int x, int y)
{
	m_nowPos.x = x;
	m_nowPos.y = y;
}

void CPlayer::SetPos(POINT pos)
{
	m_nowPos = pos;
}

void CPlayer::SetDesPos(int x, int y)
{
	m_desPos.x = x;
	m_desPos.y = y;
}

void CPlayer::SetDesPos(POINT pos)
{
	m_desPos = pos;
}

void CPlayer::DrawImage(HDC* hdc)
{
	int x,y;
	x = m_nowPos.x - m_image.GetWidth()/2;
	y = m_nowPos.y - m_image.GetHeight();
	m_image.Draw( *hdc, x, y );
}

CMyPlayer::CMyPlayer()
{
	//m_hWnd = hWnd;
}

CMyPlayer::~CMyPlayer()
{

}

bool CMyPlayer::OnTimer(int TimerID)
{
	if(TimerID == WALKTIMER)
	{
		printf( "des.x=%d,des.y=%d, now.x=%d,now.y=%d\n", m_desPos.x, m_desPos.y, m_nowPos.x, m_nowPos.y);

		if( m_desPos.x == m_nowPos.x && m_desPos.y == m_nowPos.y )
		{
			//KillTimer(m_hWnd, WALKTIMER);
		}
		else
		{
			int x, y;

			if( m_desPos.x < m_nowPos.x )
			{
				x = m_nowPos.x-1;
			}
			else if( m_desPos.x == m_nowPos.x )
			{
				x = m_nowPos.x;
			}
			else
			{
				x = m_nowPos.x+1;
			}

			if( m_desPos.y < m_nowPos.y )
			{
				y = m_nowPos.y-1;
			}
			else if( m_desPos.y == m_nowPos.y )
			{
				y = m_nowPos.y;
			}
			else
			{
				y = m_nowPos.y+1;
			}
			SetPos(x, y);
		}
		InvalidateRect(m_hWnd, NULL, false);

		return true;
	}

	return false;
}